package com.gaojiawei.multiThread14_ConcurrentHashMap;

import java.util.concurrent.ConcurrentHashMap;

/**
 * merge method
 *
 */

public class L06_ConcurrentHashMapMergeMethod {
    public static void main(String[] args) {
        ConcurrentHashMap<String, String> map = new ConcurrentHashMap<>();
        //1.if key is not exists ===>put(key,value)
        map.merge("key","value",(oldvalue,value)->{
            return "xxx";
        });
        System.out.println(map);

        //2.if key is exists and result of function is not null
        map.merge("key","value1",(oldvalue,value)->{
            return oldvalue+value;
        });
        System.out.println(map);

        //3.if key is exists and result of funciton is null
        map.merge("key","value3",(oldvalue,value)->{
            return null;
        });
        System.out.println(map);

        System.out.println(map.size());



    }

}
